package com.weilele.leisure.time.ui.holder

import android.view.View
import com.weilele.leisure.time.bean.VideoListBean
import com.weilele.leisure.time.databinding.HolderVideoItemBinding
import com.weilele.leisure.time.ui.module.video_detail.VideoDetailFragment
import com.weilele.mvvm.adapter.MvvmHolder
import com.weilele.mvvm.adapter.mvvmRcvAdapter
import com.weilele.mvvm.utils.activity.onClick
import com.weilele.mvvm.utils.activity.textFrom
import com.weilele.mvvm.utils.glide.setImageAny

class VideoItemHolder : MvvmHolder<VideoItemHolder.Bean, HolderVideoItemBinding> {
    companion object {
        fun newInstance() = mvvmRcvAdapter(VideoItemHolder::class.java, { old, new -> old == new },
            { old, new ->
                old?.data?.id == new?.data?.id
            })
    }

    constructor(binding: HolderVideoItemBinding) : super(binding)

    constructor(itemView: View) : super(itemView)

    init {
        itemView.onClick {
            VideoDetailFragment.start(it, dataWhenBind?.data)
        }
    }

    data class Bean(val data: VideoListBean.RowsDTO)

    override fun bindData(data: Bean) {
        mBinding.ivCover.setImageAny(data.data.pic)
        mBinding.name.textFrom(data.data.title)
        mBinding.tvRemark.textFrom(data.data.remarks)
    }
}